<div class="maintop">
    当前位置：商品管理
    <? if(!empty($categoryid)){ ?>
    <a href="javascript:;" action="<?=$basepath?>_add?<?=$this->page_url($page_current,$page_url)?>" class="mainFrame button icon-plus">添加</a>
    <? } ?>
    <a href="javascript:;" action="<?=$basepath?>?<?=$this->page_url($page_current,$page_url)?>" id="btn_refresh" class="mainFrame button">刷新</a>
    <? if(ISDEBUG){ ?>
        <a href="javascript:$('.debuginfo').toggle();" class="button">调试信息</a>
    <? } ?>
    <a href="/cache/update?keys=chat_products_" class="button" target="ajax" func="loadpage">更新缓存</a>
</div>
<div class="main-search">
    <table width="100%">

        <tbody><tr>
            <td>
                <form action="<?=$basepath?>" id="brandsSearch" method="get" target="ajax" dataType="html" onajax="beforeSearchForm" call="searchForm" container="#iframe" isLoad="true">
                    <select id="categoryid" name="categoryid">
                        <option value="" selected="selected">全部分类</option>
                        <? foreach($parent_category as $v){ ?>
                            <option value="<?=$v['id']?>"><?=$v['title']?></option>
                        <? } ?>
                    </select>
                    <select id="categorysubid" name="categorysubid" style="display:none">
                        <option value="" selected="selected">全部子类</option>
                    </select>
                    <input type="text" id="sKey" name="sKey" class="int" placeholder="搜索关键字">
                    每页：
                    <select id="ps" name="ps">
                        <option value="12" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 12) echo 'selected';?> >12</option>
                        <option value="20" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 20) echo 'selected';?> >20</option>
                        <option value="30" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 30) echo 'selected';?> >30</option>
                        <option value="50" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 50) echo 'selected';?> >50</option>
                        <option value="100" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 100) echo 'selected';?> >100</option>
                    </select>
                    <input type="submit" value="搜索" class="upbutton">
                    <input action="<?=$basepath?>_delete_list" type="button" id="deleteSelectId" value="删除选择" class="upbutton">
                </form>
            </td>
        </tr>
        </tbody>

    </table>
</div>
<div id="mainbody">
    <table width="100%" class="tablist">
        <tr class="trbg"><th><input id="selectAllid" type="checkbox" value="1" /></th>
            <th>商品名称</th>
            <th>网售价</th>
            <th>兑换价</th>
            <th>积分价</th>
            <th>促销价</th>
            <th>库存</th>
            <th width="40">推荐</th><th width="40">状态</th><th width="40">评论</th><th width="50">排序</th><th width="60">操作</th></tr>
        <? foreach($datas as $v){ ?>
            <tr>
                <td width="30"><input type="checkbox" name="selectValue" value="<?=$v['id']?>" /></td>
                <td class="tdleft"><?=$v['title']?></td>
                <td><?=$v['pricenet']?></td>
                <td><?=$v['price']?></td>
                <td><?=$v['pricescore']?></td>
                <td><?=$v['pricesales']?></td>
                <td><?=$v['inventory']?><?=$v['unit']?></td>
                <td><a href="<?=$basepath?>_state?id=<?=$v['id']?>&<?=$this->page_url($page_current,$page_url)?>&field=recommend" target="ajax" func="loadpage" class="upbutton state<?=$v['recommend']?>"><?=($v['recommend']?'<i class="icon-ok"></i>':'<i class="icon-cancel"></i>')?></a></td>

                <td><a href="<?=$basepath?>_state?id=<?=$v['id']?>&<?=$this->page_url($page_current,$page_url)?>&field=state" target="ajax" func="loadpage" class="upbutton state<?=$v['state']?>"><?=($v['state']?'<i class="icon-ok"></i>':'<i class="icon-cancel"></i>')?></a></td>
                <td><a href="<?=$basepath?>_state?id=<?=$v['id']?>&<?=$this->page_url($page_current,$page_url)?>&field=commentstate" target="ajax" func="loadpage" class="upbutton state<?=$v['commentstate']?>"><?=($v['commentstate']?'<i class="icon-ok"></i>':'<i class="icon-cancel"></i>')?></a></td>
                <td><?=$v['sort']?></td>
                <td>
                    <a action="<?=$basepath?>_delete?id=<?=$v['id']?>&code=<?=$v['code']?>" title="删除" class="mainFrame button icon-trash-2" href="javascript:;"></a>
                    <a action="<?=$basepath?>_edit?code=<?=$v['code']?>&categoryid=<?=$v['categoryid']?>&categorysubid=<?=$v['categorysubid']?>" title="编辑" class="mainFrame button icon-edit" href="javascript:;"></a>
                </td>
            </tr>
        <? } ?>
    </table>
    <? require VIEW.'/page.view.php' ?>
</div>
<script type="text/javascript">
    function beforeSearchForm(){
        var _key = this.sKey.value;
        if(_key.length<=0){
            //throw '搜索关键字不能为空';
        }
    }
    function searchForm(self, _html, data){
        $("#iframe").html(_html);
    }
    $(document).ready(function(){
        <?php
        if(!empty($searchdata['categoryid'])){
            echo '$("#categoryid option[value=\''.$searchdata['categoryid'].'\']").attr("selected", "selected");';
        }
        if(!empty($searchdata['categorysubid'])){
            echo '$("#categorysubid option[value=\''.$searchdata['categorysubid'].'\']").attr("selected", "selected");';
        }
        if(!empty($searchdata['sKey'])){
            echo '$("#sKey").val("'.$searchdata['sKey'].'");';
        }
        ?>
        var _default_sub_html = '';
        <?
        $_de_sub = '<option value="0" '.(intval($searchdata['categorysubid'])==0 ? ' selected="selected"':'').'>请选择</option>';
        if($sub_category && count($sub_category)){
            foreach($sub_category as $k=>$v){
                $_de_sub .= '<option value="'.$k.'" '.($k==intval($searchdata['categorysubid']) ? ' selected="selected"':'').'>'.$v['title'].'</option>';
            }
        }
        echo '_default_sub_html = \'\';';
        ?>
        $("#categoryid").change(function(){
            var _vid = $(this).val();
            var _subcategory = $("#categorysubid");
            if(parseInt(_vid)>0){
                $('#categorysubid').fadeIn(500);
                jsondata({
                    url : '/exchange/products_subcategory_search_select',
                    data : { id : _vid},
                    type : 'GET',
                    callback : function(data, textStatus, xhr){
                        var _html = '<option value="0" selected="selected">请选择</option>';
                        _subcategory.html('');
                        $.each(data,function(index,val){
                            _html += '<option value="'+val['id']+'">'+val['title']+'</option>';
                        });
                        _subcategory.html(_html);
                    }
                });
            }else{
                $('#categorysubid').fadeOut(500);
                _subcategory.html('<option value="0" selected="selected">请选择</option>');
            }
        });

    });
</script>
